package wxy.studentmanage.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import wxy.studentmanage.bean.Clazz;
import wxy.studentmanage.bean.Student;
import wxy.studentmanage.service.ClazzService;
import wxy.studentmanage.service.StudService;

import java.util.List;

@Controller
@RequestMapping("/clazz")
public class ClazzController {
    @Autowired
    @Qualifier("ClazzServiceImpl")
    private ClazzService clazzService;
    @RequestMapping("/allClazz")
    public String allClazz(Model model){
        List<Clazz> clist = clazzService.queryAllClazz();
        model.addAttribute("clist",clist);
        System.out.println(clist);
        return "allClazz";
    }
    //新增用户页面
    @RequestMapping("/toAddClazz")
    public String toAddPaper() {
        return "addClazz";
    }
    @RequestMapping("/addClazz")
    public String addPager(Clazz clazz){
        System.out.println(clazz);
        clazzService.addClazz(clazz);
        return "redirect:/clazz/allClazz";
    }
    //删除User
    @RequestMapping("/del/{userId}")
    public String deleteStud(@PathVariable("userId") int wxy_id) {
        System.out.println(wxy_id);
        int i = clazzService.deleteClazzById(wxy_id);
        System.out.println(i);
        return "redirect:/clazz/allClazz";
    }
    //更改查询
    @RequestMapping("/toUpdateClazz/{userId}")
    public String toUpdateUser(@PathVariable("userId") int wxy_id,Model model){
        System.out.println(wxy_id);
        Clazz clazz = clazzService.queryClazzById(wxy_id);
        System.out.println(clazz);
        model.addAttribute("clazz",clazz);
        return "updateClazz";
    }
    //更改更改
    @RequestMapping("/updateClazz")
    public String updateBook(Model model,Clazz clazz){
        System.out.println(clazz);
        clazzService.updateClazz(clazz);
        Clazz clazz1 = clazzService.queryClazzById(clazz.getWxy_id());
        System.out.println(clazz1);
        return "redirect:/clazz/allClazz";
    }
    /*
    *




    * */
}
